using System;
using System.Collections.Generic;
using System.Text;
using Spring.Data.Objects;
using Spring.Data.Common;
using Domain.pe.com.workspace;
using Common.Logging;
using System.Collections;

namespace DAO.pe.com.workspace.usuario.impl.procedure
{
    public class RegistrarFacturaProcedure : StoredProcedure
    {
        private static ILog logger = LogManager.GetLogger(typeof(RegistrarFacturaProcedure));
        private static string ID_PARAMETER_OUTPUT = "@id";
        public RegistrarFacturaProcedure(IDbProvider dbProvider, string procedureName)
            : base(dbProvider, procedureName)
        {    
            DeriveParameters(true);            
            Compile();
        }
        
        public virtual int ejecutar(Factura factura)
        {
            logger.Debug("iniciando ejecucion de procedure");
            int idFactura;
            object[] inParameterValues = new object[3];
            inParameterValues[0] = factura.Fecha;
            inParameterValues[1] = factura.NombreCliente;
            inParameterValues[2] = factura.Total;            
            IDictionary outParams = Query(inParameterValues);
            idFactura = (int)outParams[ID_PARAMETER_OUTPUT];
            logger.Debug("terminando ejecucion de procedure con id" + idFactura);
            return idFactura;
        }
    }
}